import select
import socket
import time

# select 把socket放入 select中,然后每当有一个连接过来,把连接conn放入select模型里面去

port = 19834
ip = "127.0.0.1"

ss = socket.socket()
ss.bind((ip, port))
ss.listen(10)

readable_list = [ss]


while 1:
    # print('listen again')
    rlist, wlist, xlist = select.select(readable_list, [], [],5)
    # 如果遍历出来的
    print('listen to the readable sockets',rlist)
    print('length of the readable sockets',len(rlist))
    print('length of the total sockets', len(readable_list))
    for i in rlist:
        if i is ss:
            #如果ss准备就绪,那么说明ss就可以接受连接了,当ss接受到连接
            #那么把连接返回readlist
            conn,addr = i.accept()
            readable_list.append(conn)
